package net.starwifi.duobao.listener;

import net.starwifi.duobao.jms.dto.SmsMessage;
import net.starwifi.duobao.utils.sms.SMSUtils;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/29.
 */
public class JmsReceiveListener implements MessageListener {


    @Override
    public void onMessage(Message message) {
        try {
            TextMessage tm = (TextMessage) message;
            if(message!=null){
                 SmsMessage smsContent=SmsMessage.parse(tm.getText());
                 sendSms(smsContent);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void sendSms(SmsMessage smsMessage){
        List<String> dataList=new ArrayList<String>();
        dataList.add(smsMessage.getContent());
        dataList.add(smsMessage.getContentTwo());
        SMSUtils.send(smsMessage.getMobile(), dataList, "10016");
    }
}
